package com.spy.dish.controller;

import com.spy.common.core.domain.R;
import com.spy.dish.dto.DishDTO;
import com.spy.dish.dto.DishQueryDTO;
import com.spy.dish.vo.DishDetailVO;
import com.spy.dish.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import java.util.List;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spy.common.annotation.Log;
import com.spy.common.core.controller.BaseController;
import com.spy.common.core.domain.AjaxResult;
import com.spy.common.enums.BusinessType;
import com.spy.dish.service.IDishService;
import com.spy.common.core.page.TableDataInfo;

/**
 * 菜品信息Controller
 *
 * @author zhaoxy
 * @date 2025-11-10
 */
@RestController
@RequestMapping("/dish/dishInfo")
@Api(tags = "菜品信息相关接口")
public class DishController extends BaseController
{
    @Autowired
    private IDishService dishService;

/**
 * 查询菜品信息列表
 */
@PreAuthorize("@ss.hasPermi('dish:dishInfo:list')")
@GetMapping("/list")
@ApiOperation("查询菜品信息列表")
    public TableDataInfo<DishVO>  list(@ApiParam(value = "菜品信息查询条件") DishQueryDTO dishQueryDTO)
    {
        //startPage();
        TableDataInfo<DishVO>  list = dishService.selectDishList(dishQueryDTO);
        return list;
    }


    /**
     * 获取菜品信息详细信息，包括原料和步骤信息
     */
    @PreAuthorize("@ss.hasPermi('dish:dishInfo:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取菜品信息详细信息，包括原料和步骤信息")
    public R<DishDetailVO> getInfo(@ApiParam(value = "菜品信息ID", required = true)
                                   @PathVariable("id") Long id) {
        return R.ok(dishService.selectDishDetailById(id));
    }

    /**
     * 新增菜品详细信息
     */
    @PreAuthorize("@ss.hasPermi('dish:dishInfo:add')")
    @Log(title = "菜品信息", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增菜品信息")
    public AjaxResult add(@ApiParam(value = "菜品信息实体", required = true) @RequestBody DishDTO dishDTO) {
        dishService.saveDishDetail(dishDTO);
        return success();
    }

    /**
     * 修改菜品信息
     */
    @PreAuthorize("@ss.hasPermi('dish:dishInfo:edit')")
    @Log(title = "菜品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改菜品信息")
    public AjaxResult edit(@ApiParam(value = "菜品信息实体", required = true) @RequestBody DishDTO dishDTO) {
        return toAjax(dishService.updateDishDetail(dishDTO));
    }

    /**
     * 删除菜品详细信息
     */
    @PreAuthorize("@ss.hasPermi('dish:dishInfo:remove')")
    @Log(title = "菜品信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("批量删除菜品详细信息")
    public AjaxResult remove(@ApiParam(value = "菜品信息ID数组", required = true) @PathVariable Long[] ids) {
        return toAjax(dishService.deleteDishDetailByIds(ids));
    }

    /**
     * 菜品启用/禁用
     */
    @PutMapping("/status")
    @ApiOperation("菜品启用/禁用")
    public AjaxResult changeStatus(@ApiParam(value = "菜品信息实体", required = true) @RequestBody DishDTO dishDTO) {
        return toAjax(dishService.updateDishDetail(dishDTO));
    }
}